package com.itheima.day14.第三题;

public class MyRunnable implements Runnable {
    private int stick = 100;
    @Override
    public void run() {
        while (true){
            //定义同步代码块
            synchronized ("stick"){
                if (stick == 0){
                    break;
                }else {
                    stick--;
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread().getName() + "正在售票，还剩" + stick + "张票");
                }
            }
        }
    }
}
